from pydub import AudioSegment

def trans(filepath, ori:str,hz:str):
    song = AudioSegment.from_file(filepath, format=ori)
    name = filepath.split("/")[-1]
    song.export(f"{name}." + str(hz), format=str(hz))

def trans_mp3_to_other(filepath, hz):
    song = AudioSegment.from_mp3(filepath)
    song.export("Newsound." + str(hz), format=str(hz))


def trans_wav_to_other(filepath, hz):
    song = AudioSegment.from_wav(filepath)
    song.export("Newsound." + str(hz), format=str(hz))


def trans_ogg_to_other(filepath, hz):
    song = AudioSegment.from_ogg(filepath)
    song.export("Newsound." + str(hz), format=str(hz))


def trans_flac_to_other(filepath, hz):
    song = AudioSegment.from_file(filepath)
    song.export("Newsound." + str(hz), format=str(hz))


def trans_m4a_to_other(filepath, hz):
    song = AudioSegment.from_file(filepath)
    song.export("Newsound." + str(hz), format=str(hz))


# 参数1：音频路径， 参数2：转换后的格式
#trans_m4a_to_other("./20240112_134747.m4a", "wav")







# song = AudioSegment.from_mp3("音频/asmr/6-26.m4a")
# print("%%%%%%%%%")
# print(song.duration_seconds)
# # 切片
# t1 = song[:340000]

# t2 = song[348000:]

# #t=t1
# t=t1+t2
# print("%%%%%%%%%")
# print(t.duration_seconds)
# t.export("ans11.mp3", format="mp3")